﻿using System;

namespace Program19
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入你要判断的数：");
            int i = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(IsPrime(i));
            Console.WriteLine(PrimeNumber(i));
        }


        public static bool IsPrime(int n)
        {
            if (n < 2 && n>0)
            {
                return false;
            }
            else 
            {
                for (int i = 2; i <= n / 2; i++)
                {
                    if (n % i == 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
        /// <summary>
        /// 计算质数
        /// </summary>
        /// <param name="n">计算范围</param>
        /// <returns>质数和</returns>
        public static string PrimeNumber(int n)
        {
            string primes = "质数为:";
            int o = 0;
            for(int i = 1; i <= n; i++)
            {
                if (IsPrime(i)) 
                {
                    primes += i + "|";
                    o += i;
                }
            }
            return primes + "质数和为" + o;
        }
    }
}
